<?php
session_start();
ob_start();
?>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Thông Báo</title>
    <link href="../CSS/dk.css" rel="stylesheet" type="text/css">
</head>
    <body>
<?php
include("../dbcon.php");
  if($_POST) {
		$id 		= $_POST['username'];
		$password 	= md5($_POST['password']);
		$email 		= $_POST['email']; 
		$ho 		= $_POST['ho'];
		$tenlot 	= $_POST['tenlot'];
		$ten		= $_POST['ten'];
		$diachi		= $_POST['diachi'];
		$sdt 		= $_POST['sdt'];
		$gt 		= $_POST['hiddengt'];
		$cauhoi		= md5($_POST['cauhoi']);
		$traloi		= md5($_POST['traloi']);
		$captcha	= $_POST['txtCaptcha'];
		if($captcha != $_SESSION['security_code'])
		{
			echo '<div class="bgdk"><center><h1>Captcha không đúng .</h1></center>
					<a href="../TB/dangky.php">Quay lại</a></div>';
		}
		else
		{
			$a=mysql_query("select * from user where username='{$id}'");
			if (mysql_num_rows($a)==1)
			{
				echo '<div class="bgdk"><center><h1>Tên đăng nhập đã tồn tại .</h1></center>
					<a href="../TB/dangky.php">Quay lại</a></div>'; 
			}
			else
			{
				mysql_query("START TRANSACTION"); 
				
				$b=mysql_query("insert into user(username,password,cauhoi,traloi) values('{$id}','{$password}','{$cauhoi}','{$traloi}')");
				$c=mysql_query("insert into khachhang(ho,ten,tenlot,sdt,gioitinh,email,id,diachi) values('{$ho}','{$ten}','{$tenlot}','{$sdt}','{$gt}','{$email}','{$id}'),'{$diachi}'");
				if($b&&$c)
				{ 
					mysql_query("COMMIT");
					echo '<div class="bgdk"><center><h1>Đăng kí thành công .</h1></center></div>';
				}
				else
				{ 
					mysql_error();
					mysql_query("ROLLBACK");
					echo '<div class="bgdk"><center><h1>Đăng kí thất bại .</h1></center></div>';
				}
			}
		}
  }
ob_end_flush();
?>
</body>
</html>
